package com.ymatou.iapi.godmch.testcase;

import java.util.List;

import org.json.JSONException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.bindmchBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.parameter.getAfterServiceInfoBean;
import com.ymatou.iapi.godmch.service.CreateCodeCall;
import com.ymatou.iapi.godmch.service.getAfterServiceInfoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.afterserviceinfo;
import com.ymttest.database.model.afterserviceinfoExample;
import com.ymttest.database.sqlwapper.godmch.afterserviceinfoWapper;
/**
*查询售后信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getAfterServiceInfo{
	private static getAfterServiceInfoBean bean;
	private static getAfterServiceInfoCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询售后信息");
	}

	@Before
	public void caseUp() {
		bean=new getAfterServiceInfoBean();
		call=new getAfterServiceInfoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
    private void  check_verify() throws InterruptedException, JSONException
    {
    	Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
    	afterserviceinfo return_info=call.getResult();
    	afterserviceinfoWapper infoWapper=new afterserviceinfoWapper();
		afterserviceinfoExample Example=new afterserviceinfoExample();
		afterserviceinfoExample.Criteria criteria = Example.createCriteria();
		criteria.andMchIdEqualTo(bean.getMchId());
		criteria.andParentMchIdEqualTo(bean.getParentMchId());
	
		afterserviceinfo DB_infos=infoWapper.selectByExample(Example).get(0);
		Logger.verifyEquals(DB_infos.getAddress(), return_info.getAddress(), "验证Address");
		Logger.verifyEquals(DB_infos.getMchId(), return_info.getMchId(), "验证MchId");
		Logger.verifyEquals(DB_infos.getRemark(), return_info.getRemark(), "验证Remark");
		Logger.verifyEquals(DB_infos.getWeChat(), return_info.getWeChat(), "验证WeChat");
    }
    
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAfterServiceInfo_001() {
		Logger.start(true,"正例-查询售后信息-mchId是渠道");
		try {

			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean2);
			//创建渠道
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			//新增售后服务
			GodmchManageCallService.AddAfterService(mchId,mchId);
			
			bean.setParentMchId(mchId);
			bean.setMchId(mchId);
			call.setData(bean);
			call.callService();		
			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAfterServiceInfo_002() {
		Logger.start(true,"正例-查询售后信息-mchId是渠道+代理");
		try {
			//代理用户
			UserCreateBean usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean);
			usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId_agent = DGUserCallService.UserCreateCall(usercreateBean);
			
			CreateCodeBean codebean=GodmchManageCallService.CreateAllMsgSellerMch();
			codebean.setIsPermanently(false);
			CreateCodeCall codeCall=GodmchManageCallService.createCodeCall(codebean);
			//创建渠道1
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			//渠道1 邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(mchId, true);
			CreateCodeCall createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);
			//创建渠道2
		    createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId_agent);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			//绑定一个渠道与另外一个渠道绑定
			bindmchBean bindmchBean=GodmchManageCallService.InitbindmchBean(mchId_agent, createCodeCall.getCode());
			GodmchManageCallService.bindmchcall(bindmchBean);
			
			//新增售后服务
			GodmchManageCallService.AddAfterService(mchId,mchId_agent);
			
			bean.setParentMchId(mchId);
			bean.setMchId(mchId_agent);
			call.setData(bean);
			call.callService();		
			
			check_verify();		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAfterServiceInfo_003() {
		Logger.start(true,"正例-查询售后信息-mchId是代理");
		try {

			//代理用户
			UserCreateBean usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean);
			usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId_agent = DGUserCallService.UserCreateCall(usercreateBean);
			
			CreateCodeBean codebean=GodmchManageCallService.CreateAllMsgSellerMch();
			codebean.setIsPermanently(false);
			CreateCodeCall codeCall=GodmchManageCallService.createCodeCall(codebean);
			//创建渠道1
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			//渠道1 邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(mchId, true);
			CreateCodeCall createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);
			
			List<createmchBean>  createmchList=GodmchManageCallService.InitcreatemchBeanForAgent(mchId, mchId_agent);
			GodmchManageCallService.createmchCallForAgent(createmchList.toArray(new
					createmchBean[0]));
			
			//新增售后服务
			GodmchManageCallService.AddAfterService(mchId,mchId_agent);
			
			bean.setParentMchId(mchId);
			bean.setMchId(mchId_agent);
			call.setData(bean);
			call.callService();		
			
			check_verify();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAfterServiceInfo_004() {
		Logger.start(true,"正例-查询售后信息-mchId不存在,parentMchId存在");
		try {
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean2);
			//创建渠道
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			//新增售后服务
			GodmchManageCallService.AddAfterService(mchId,mchId);
			
			bean.setParentMchId(mchId);
			bean.setMchId(99999911);
			
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证Message");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAfterServiceInfo_004_1() {
		Logger.start(true,"正例-查询售后信息-mchId存在,parentMchId不存在");
		try {
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean2);
			//创建渠道
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			//新增售后服务
			GodmchManageCallService.AddAfterService(mchId,mchId);
			
			bean.setParentMchId(99999911);
			bean.setMchId(mchId);
			
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证Message");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAfterServiceInfo_005() {
		Logger.start(true,"正例-查询售后信息-mchId为空");
		try {
			
			//bean.setMchId(99999911);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("参数异常"), "验证Message");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}